﻿#pragma once

#include "../../MirControls/MirImageControl.h"
#include "../../MirControls/MirGameShopCell.h"
#include "../../MirControls/MirLabel.h"
#include "../../MirControls/MirButton.h"
#include "../../../Shared/Data/ItemData.h"
#include "../../MirControls/MirTextBox.h"
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <any>

using namespace Client::MirControls;
using namespace Client::MirGraphics;
using namespace Client::MirNetwork;
using namespace Client::MirSounds;
namespace C = ClientPackets;

namespace Client::MirScenes::Dialogs
{
    class GameShopDialog final : public MirImageControl
    {
    public:
        GameShopViewer *Viewer;
        MirLabel *PageNumberLabel, *totalGold, *totalCredits;
        MirButton *ALL, *War, *Sin, *Tao, *Wiz, *Arch;
        MirButton *allItems, *topItems, *Deals, *New;
        MirButton *CloseButton, *PreviousButton, *NextButton;
        MirButton *UpButton, *DownButton, *PositionBar;


        std::vector<GameShopCell*> Grid;
        std::vector<MirLabel*> Filters = std::vector<MirLabel*>(22);
    private:
        std::vector<std::string> CategoryList = std::vector<std::string>();
        std::vector<GameShopItem*> filteredShop = std::vector<GameShopItem*>();
        std::vector<GameShopItem*> SearchResult = std::vector<GameShopItem*>();
    public:
        MirTextBox *Search;
        MirImageControl *TitleLabel, *FilterBackground;

        std::string ClassFilter = "Show All";
        std::string TypeFilter = "Show All";
        std::string SectionFilter = "Show All";

        int StartIndex = 0;
        int Page = 0;
        int CStartIndex = 0;
        Decimal maxPage = 0;

        virtual ~GameShopDialog()
        {
            delete Viewer;
            delete PageNumberLabel;
            delete totalGold;
            delete totalCredits;
            delete ALL;
            delete War;
            delete Sin;
            delete Tao;
            delete Wiz;
            delete Arch;
            delete allItems;
            delete topItems;
            delete Deals;
            delete New;
            delete CloseButton;
            delete PreviousButton;
            delete NextButton;
            delete UpButton;
            delete DownButton;
            delete PositionBar;
            delete Search;
            delete TitleLabel;
            delete FilterBackground;
        }

        GameShopDialog();

        void Hide() override;
        void Show() override;

    protected:
        void Dispose(bool disposing) override;

    public:
        void Process();


        void FilterScrolling(std::any sender, MouseEventArgs *e);

    private:
        void UpdatePositionBar();

        void PositionBar_OnMoving(std::any sender, MouseEventArgs *e);

    public:
        void ResetTabs();

        void ResetClass();

        void GetCategories();

        void SetCategories();
        void UpdateShop();

    };
}
